<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use hema\Tree;

class Index extends Frontend
{
	protected $model = null;
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'index';
    protected $rulelist = [];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Link');
        // 必须将结果集转换为数组
        $link = collection($this->model->order('weigh desc,id desc')->select())->toArray();
        $this->view->assign('link', $link);
        
        $this->model = model('UserRule');
        // 必须将结果集转换为数组
        $ruleList = collection($this->model->where(['status' => 'normal','ismenu' => 1,'name' =>['like','index%']])->order('weigh desc,id desc')->select())->toArray();
        $this->rulelist = Tree::instance()->getMenuTree($ruleList);
        $this->view->assign('menudata', $this->rulelist);
    }

    public function index()
    {
        $this->view->assign('key', 'index');
        $this->view->assign('title', __('Frontend'));
        return $this->view->fetch();
    }

}
